/********************************************************************

Class: Singleton< Ty > - C++ implementation of Singleton

Write Date: 2011/07/21
Author: Deng Nianchen
>>>> Implements basic Singleton design pattern.

Modify Date: 2015/04/14
Author: Apple
>>>> Remove the inherit relationship between Singleton and Object
>>>> Rename getSingleton() to ref() and remove getSingletonPtr()
>>>> Update the style of document and code
*********************************************************************/
#pragma once
#include "ooputils_global.h"



_NS_OOP_BEGIN



/**
 * Class Singleton implements application-slope object management.
 * All classes derived from it will only have one object when the application is 
 * running. You can use an singleton object anywhere by call ref(). You cannot 
 * an singleton object or destruct it manually. It will be automatically created 
 * when you first use it and be destoried when the application exits.
 * Class inherited from Singleton must: 
 * 1. Only have private or protected default constructor;
 * 2. Not have copy constructor or assignment operator;
 * 3. Make Singleton< > as its friend class.
 *
 * Thread-safe: not valid.
 *
 * @remarks 2015/04/14, Apple
 */
template< class T >
class Singleton
{
public:

	/**
	 * Get the reference to the single instance.
	 *
	 * @return the reference to the single instance
	 */
	static T& ref () {
		static T singleton;
		return singleton;
	}

protected:

	/**
	 * The default constructor.
	 *
	 * @return 
	 */
	Singleton () {}

	/**
	* The copy constructor.
	*/
	Singleton (Singleton&) {}

	/**
	* The assignment operator.
	*/
	Singleton& operator= (Singleton&) { return (*this); }

};



_NS_OOP_END